//
//  MyInfoController.m
//  FinancialProduct
//  我的资料
//  Created by Stella on 2017/8/30.
//  Copyright © 2017年 maq. All rights reserved.
//
#import "UserModel.h"
#import "HandleNetProduct.h"
#import "MyAccountCell.h"
#import "MyInfoController.h"
#import "CKPuslichTool.h"
#import "ChangeUserInfoController.h"

@interface MyInfoController ()
@property (strong,nonatomic) NSArray *DataArray;
@property (strong,nonatomic) NSArray *textArray;
@property (weak, nonatomic) IBOutlet UITableView *mTableView;
@property (strong,nonatomic) NSDictionary *userInfoDic;
@end

@implementation MyInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([[UserModel getUser].Accountstatus intValue]== 2) {
        self.DataArray=@[@"姓名",@"证件类型",@"证件号码",@"证件有效期",@"移动电话"];
    }else{
        self.DataArray=@[@"姓名",@"性别",@"拼音/英文-姓",@"拼音/英文-名",@"证件类型",@"证件号码",@"是否永久有效",@"证件有效期",@"出生日期",@"国籍",@"财富顾问",@"移动电话"];
    }
    
    
    [self getMyInfo];
}
-(void)getMyInfo{
    UserModel *model=[UserModel getUser];
    
    int mid=[model.CustomerID intValue];
    NSDictionary *params=@{@"AAAMethodName":@"MyInformation",@"CustomerID":@(mid),@"AccountStatus":model.Accountstatus};
    [HandleNetProduct getListforParams:params Success:^(NSArray *data) {
        /**
         AccountName = "陈烨";
         AccountSex = "女";
         EnglishName = ye;
         EnglishSurname = Chen;
         IDDocumenttype = "身份证";
         IDNumber = 310110198807055625;
         IsForever = "否";
         MainMobilephone = "";
         Mainlyphone = "";
         MainlyphoneAreaCode = "";
         Nationality = "中国";
         PersonEmail = "";
         PreferredAddress = "浦东新区世纪大道1600号2幢4楼";
         PreferredAddress1 = "浦东新区世纪大道1600号2幢4楼";
         PreferredCity = "上海";
         PreferredCountry = "中国";
         PreferredProvince = "上海";
         PreferredZip = 200000;
         PreferredZip1 = 200000;
         UserName = "总部客户";
         aIDEffectDate = "2035-03-01";
         date = "1988-07-05";
         **/
        if (data.count >0) {
            NSDictionary *dic=data[0];
            self.userInfoDic=dic;
            if ([[UserModel getUser].Accountstatus intValue]== 2) {
                self.textArray=@[dic[@"AccountName"],dic[@"IDDocumenttype"],dic[@"IDNumber"],dic[@"aIDEffectDate"],dic[@"MainMobilephone"]];
            }else{
            self.textArray=@[dic[@"AccountName"],dic[@"AccountSex"],dic[@"EnglishSurname"],
                                 dic[@"EnglishName"],dic[@"IDDocumenttype"],dic[@"IDNumber"],
                                 dic[@"IsForever"],dic[@"aIDEffectDate"],dic[@"date"],
                                 dic[@"PreferredCountry"],dic[@"UserName"],dic[@"MainMobilephone"]];
            }
            //NSLog(@"getMyInfo--%@",data);
            [self.mTableView reloadData];
        }
        
    } Failure:^(NSString *errorInfo) {
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if ([[UserModel getUser].Accountstatus intValue]==2) {
        return 1;
    }
    return 2;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (section==0) {
        return self.DataArray.count;
    }
    return 1;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0){
        MyAccountCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MyAccountCell" forIndexPath:indexPath];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType=UITableViewCellAccessoryNone;
        cell.NameLabel.text=self.DataArray[indexPath.row];
        cell.RightLabel.text=self.textArray[indexPath.row];;
        cell.jiantou.hidden=YES;
        return cell;
    }else{
        MyAccountCell *cell=[tableView dequeueReusableCellWithIdentifier:@"MyAccountCell" forIndexPath:indexPath];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType=UITableViewCellAccessoryNone;
        cell.NameLabel.text=@"联系方式及邮箱";
        cell.RightLabel.text=@"";
        cell.jiantou.hidden=NO;
        return cell;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10.0;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==1) {
        //联系方式及邮箱
        ChangeUserInfoController *vc=(ChangeUserInfoController *)[CKPuslichTool getViewControllerFromStroyBoard:@"Setting" viewID:@"ChangeUserInfoController"];
        vc.userInfo=self.userInfoDic;
        [self.navigationController pushViewController:vc animated:YES];
    }
}


@end
